package softserve.vgolosh.utils;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class PropertiesHelper {
	private static Boolean initialised = false;
	private static Properties properties = new Properties();
	public static String WORKING_DIR = "d:\\svnwork\\customers\\";
	public static String TRUNK_WORKING_DIR = "d:\\svnwork\\customers\\trunk\\working\\";
	static {
		try {
			properties.load(new FileInputStream("project.properties"));
			initialised = true;
		} catch (FileNotFoundException e) {
			System.out
					.println("No project.properties file found. using defaults");
		} catch (IOException e) {
			e.printStackTrace();
		}
		try {
			TRUNK_WORKING_DIR = PropertiesHelper.getProperty("TRUNK_WORKING_DIR");
		} catch (PropertyNotFoundException e) {
			System.out.println(e);
			System.out.println("using default value " + TRUNK_WORKING_DIR);
		}
		try {
			WORKING_DIR = PropertiesHelper.getProperty("SVN_WORK_PATH");
		} catch (PropertyNotFoundException e) {
			System.out.println(e);
			System.out.println("using default value " + WORKING_DIR);
		}
	}

	public static String getProperty(String key)
			throws PropertyNotFoundException {
		if (properties.containsKey(key)) {
			return properties.getProperty(key);
		} else {
			throw new PropertyNotFoundException(key);
		}
	}

	public static Boolean isInitialised() {
		return initialised;
	}
}
